package com.example.demowx.utils;

import com.alibaba.fastjson.JSONObject;
import com.example.demowx.model.*;
import com.example.demowx.service.DemoWxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import sun.security.provider.Sun;

/**
 * @author pengyifeng
 * @version 1.0.0
 * @ClassName CreateMenu.java
 * @Description 创建菜单demo, 换到test模块中生成
 * @createTime 2020年11月25日 14:37:00
 */
public class CreateMenu {

    public static void main(String[] args) {

        //菜单对象
        Button button = new Button();
        //第一个一级菜单
        button.getButton().add(new ClickButton("一级点击", "1"));
        //第二个一级菜单
        button.getButton().add(new ViewButton("一级跳转", "http://www.baidu.com"));
        //创建第三个一级菜单
        SubButton subButton = new SubButton("有子菜单");
        //为第三个一级菜单添加子菜单 key是自己定义
        subButton.getSub_button().add(new PhotoOrAlbumButton("传图", "31"));
        subButton.getSub_button().add(new ClickButton("点击", "32"));
        subButton.getSub_button().add(new ViewButton("网易新闻", "http://news.163.com"));
        //加入第三个一级菜单
        button.getButton().add(subButton);
        //转为json
        Object o = JSONObject.toJSON(button);
        //准备url
        String menuUrl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";
        //menuUrl.replace("ACCESS_TOKEN",demoWxService.getAccessToken());
        String post = MyUtil.post(menuUrl, o.toString());
        System.out.println(post);


    }
}
